
/**
 * 基础输入对象
 */
interface AjaxResponse<T> {
    /**
     * 请求是否成功
     */
    success: boolean;
    /**
     * 请求回应
     */
    result: T;
    /**
     * 错误信息
     */
    error: ErrorInfo;
}

/**
 * 错误
 */
interface ErrorInfo {
    /**
     * 错误代码
     */
    code: number;
    /**
     * 错误描述
     */
    message: string;
    /**
     * 错误详情
     */
    details: string;
    /**
     * 验证错误
     */
    validationErrors: Array<ValidationErrorInfo>;
}

/**
 * 验证错误
 */
interface ValidationErrorInfo {
    /**
     * 错误描述
     */
    message: string;
    /**
     * 错误变量
     */
    members: Array<string>;
}

/**
 * 返回列表基础接口
 */
interface ListResponse<T> extends BaseResponse {
    list: Array<T>;
    total: number;
}

interface BaseResponse {
    extData: any;
}

/**
 * 辅助分页
 */
interface IPaginationOptions {
    /**
     * 分页中需要跳过的项数
     */
    skipSize: number;
    /**
     * 每页需显示的项数
     */
    pageSize: number;
    /**
     * 当前页数
     */
    currentPage: number;
}

/**
 * 视图模型必须实现的接口
 */
interface IBaseViewModel<TQueryTerms> extends ng.IScope {
    /**
     * 是否正在查询中
     */
    querying: boolean;
    /**
     * 查询函数
     */
    queryFunc: () => void;
    /**
     * 标题
     */
    title: string;
    /**
     * 查询条件
     */
    queryTerms: TQueryTerms;
}

abstract class ListController<TViewModel extends IBaseViewModel<TQueryTerms>, TQueryTerms> {
    /**
     * 分页参数
     */
    protected paginationOptions: IPaginationOptions;
    /**
     * 查询条件
     */
    protected queryTerms: TQueryTerms;

    constructor(protected $scope: TViewModel) {

    }

    /**
     * 初始化
     */
    protected init(): void {
        this.$scope.querying = false;
        this.$scope.queryFunc = this.query;
        this.paginationOptions = {
            skipSize: 0,
            pageSize: 10,
            currentPage: 1
        };
    }

    /**
     * 分页
     */
    protected paginationChanged = (newPage: number, pageSize: number) =>  {
        this.paginationOptions.skipSize = newPage * pageSize - pageSize;
        this.paginationOptions.pageSize = pageSize;
        this.paginationOptions.currentPage = newPage;
        this.loadData(this.queryTerms, this.paginationOptions.skipSize, this.paginationOptions.pageSize);
    }

    /**
     * 查询
     */
    query = () => {
        this.$scope.querying = true;
        this.queryTerms = this.$scope.queryTerms;
        this.loadData(this.queryTerms, 0, this.paginationOptions.pageSize);
    }

    protected abstract loadData(queryTerms: TQueryTerms, skip: number, count: number): void;
}

/**
 * ------------------枚举部分
 */

/**
 * 专员类型
 */
enum CommissionerType {
    /**
     * 缺省值
     */
    None = 0,
    /**
     * 计划专员
     */
    Plan = 1,
    /**
     * 调度专员
     */
    Dispatch = 2,
    /**
     * 调度经理
     */
    DispatchManager = 3,
    /**
     * 客服专员
     */
    CustomerService = 4,
    /**
     * 商务专员
     */
    BusinessAffairs = 5,
    /**
     * 结算专员
     */
    Settler = 6,
    /**
     * 独立专员
     */
    Independent = 7,
    /**
     * 客服经理
     */
    CustomerManager = 8
}

/**全局变量 */
declare var BMap;
declare var BMAP_ANCHOR_BOTTOM_LEFT;
declare var BMAP_NAVIGATION_CONTROL_LARGE;